package com.basic.java.threads.sync.unsafe;

import java.util.ArrayList;
import java.util.List;

/**
 * 线程不安全的List 类
 * 创建时间：2022/4/19 22:57
 *
 * @author gejin
 */
public class UnsafeList {
    public static void main(String[] args) {
        List<Integer> list = new ArrayList<Integer>();
        for (int i = 0; i < 10000; i++) {
            int finalI = i;
            new Thread(() -> {
                list.add(finalI);
            }).start();
        }
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(list.size());
    }
}
